using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;
using Acms.SqlDal;

namespace Acms.Bll
{
    public class SearchTerm : BaseItem
    {
        private SearchTerm() : base() { }
        private SearchTerm(Hashtable table) : base(table) { }
        private SearchTerm(Hashtable table, List<SearchTerm> collection) : base(table, collection) { }

        protected override Base CreateDal()
        {
            return new SearchTermDal();
        }
        
        public static SearchTerm CreateInstance(int siteId, string term)
        {
            SearchTerm tmp = new SearchTerm();
            tmp.siteId = siteId;
            tmp.term = term;
            return tmp;
        }

        private static SearchTerm Get(Hashtable table)
        {
            if (table != null)
            {
                return new SearchTerm(table);
            }
            else
            {
                return null;
            }
        }

        private static List<SearchTerm> Get(Hashtable[] tables)
        {
            List<SearchTerm> tmp = new List<SearchTerm>();
            if (tables != null)
            {
                foreach (Hashtable table in tables)
                {
                    tmp.Add(new SearchTerm(table, tmp));
                }
            }
            return tmp;
        }

        public static List<SearchTerm> GetAllBySiteId(int siteId)
        {
            SearchTermDal dal = new SearchTermDal();
            return Get(dal.GetAllBySiteId(siteId));
        }

        public new void Update()
        {
            base.Update();
        }

        protected override void SaveChanges(ref object concurencyId, Base dal)
        {
            ((SearchTermDal)dal).Update(siteId, term, ref id, ref count);
        }

        protected override void Load(Hashtable table)
        {
            id = (int)table[SearchTermDal.Fields.Id];
            siteId = (int)table[SearchTermDal.Fields.SiteId];
            term = (string)table[SearchTermDal.Fields.Term];
            count = (int)table[SearchTermDal.Fields.Count];
        }

        private int id;
        public int Id
        {
            get { return id; }
        }

        private int siteId;
        public int SiteId
        {
            get { return siteId; }
        }

        private int count;
        public int Count
        {
            get { return count; }
        }

        private string term;
        public string Term
        {
            get { return term; }
        }
	
	
    }
}
